/**
 * 潮自拍页面方法 - 确认页
 */
var selfiecitypagesure = {};

/**
 * @function 确认页点击保存
 * 1.调用前,确认页
 * 2.调用后,拍摄页
 * @param {opt_timeout} Number 保存等待时间
 */
selfiecitypagesure.surePageTapSaveBtn = function (opt_timeout) {
    var waitTime = opt_timeout || 10;                  //等待时长
    var takePhotoTime = 60;                            //拍照时间
    var retryCount = 5;                                //尝试点击保存次数

    //等待拍照
    while (!selfiecityelementsure.surePageSaveBtn()().isEnabled()
        && takePhotoTime > 0) {
        uiaoverwrite.target.delay(1);
        takePhotoTime --;
    }
    if (takePhotoTime == 0) {
        throw new AssertionException("应用页面卡住:拍照时长超过1分钟");
    }

    selfiecitycommon.printLog('确认页点击保存图片');
    while (selfiecityelementsure.surePageSaveBtn()().isValid()) {
        if (retryCount == 0) {
            throw new AssertionException('应用页面卡住:确认页保存失败');
        }
        uiaoverwrite.elemenTapSafe(
            selfiecityelementsure.surePageSaveBtn());
        //等待保存的时间
        waitTime = opt_timeout || 10;
        while (selfiecityelementsure.surePageSaveBtn()().isValid()
            && waitTime > 0) {
            uiaoverwrite.target.delay(1);
            waitTime --;
        }
        retryCount --;
        //弹框处理
        selfiecitycommon.evaluateAlertOpeartor();
        if (selfiecityelementshoot.shootPageShootBtn()().isVisible()) {
            break;
        }
    }
}

/**
 * @function 确认页点击打钩
 */
selfiecitypagesure.surePageTapSureBtn = function () {
    var retryCount = 5;             //尝试次数
    var waitTime = 30;              //等待时长

    while (selfiecityelementsure.surePageSureBtn()().isValid()) {
        waitTime = 30;
        if (retryCount == 0) {
            return false;
        }
        selfiecitycommon.printLog('确认页点击打钩');
        uiaoverwrite.elemenTap(
            selfiecityelementsure.surePageSureBtn());
        while (waitTime > 0) {
            uiaoverwrite.target.delay(1);
            if (!selfiecityelementsure.surePageSureBtn()().isValid()) {
                return true;
            }
            waitTime--;
        }
        selfiecitypagesure.surePageTapBackBtn();            //返回拍摄页
        selfiecitypageshoot.shootPageTapShootBtn(30, 20);   //进行拍摄
        retryCount--;
    }
}

/**
 * @function 确认页点击分享
 */
selfiecitypagesure.surePageTapShareBtn = function () {
    selfiecitycommon.printLog('点击分享键');
    uiaoverwrite.tapElementAToWaitElementBVisible(
        selfiecityelementsure.surePageShareBtn(), undefined,
        selfiecityelementshare.sharePageContinueBtn(), undefined);
    selfiecitycommon.appAlertOpeartor();
}

/**
 * @function 确认页点击返回
 * 1.调用前,确认页
 * 2.调用后,拍摄页
 */
selfiecitypagesure.surePageTapBackBtn = function () {
    selfiecitycommon.printLog('确认页点击返回');
    uiaoverwrite.tapElementToWaitNotVisible(
        selfiecityelementsure.surePageBackBtn());
}

/**
 * @function 确认页点击随机特效按钮
 * @param {clickCount} Number 点击次数
 * @param {intervalTime} Float 间隔时间
 */
selfiecitypagesure.surePageTapRandomEff = function (clickCount, intervalTime) {
    var defaultTime = intervalTime || 1;              //间隔时间

    for (var j = 0; j < clickCount; j++) {
        selfiecitycommon.printLog('点击确认页随机特效第' + (j + 1) + '次');
        uiaoverwrite.elemenTap(
            selfiecityelementsure.surePageRandomEffBtn());
        uiaoverwrite.target.delay(defaultTime);
    }
}